package com.example.rest.job;

import com.example.base.job.IJob;
import com.example.base.job.IJobMap;
import com.example.base.websocket.SocketModel;
import com.example.rest.websocket.BaseAppWebSocketUtils;
import com.example.rest.websocket.WebSocket;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;

import java.io.IOException;
import java.util.List;

@Slf4j
public class WebSocketJob implements IJob {
    @Override
    public String getDesc() {
        return "websocketjob";
    }

    @Override
    public void exec(IJobMap iJobMap) {
        WebSocket webSocket=BaseAppWebSocketUtils.getAppWebSocket();
        if(webSocket!=null){
            List<SocketModel> socketModelList=webSocket.getWebSocketSessionByApp();
            socketModelList.forEach(e->{
                WebSocketSession session=e.getWebSocketSession();
                try {
                    session.sendMessage(new TextMessage("base job 发送消息---->" +
                            ""));
                } catch (IOException ioException) {
                    ioException.printStackTrace();
                }
            });
        }
    }

    @Override
    public String getJobName() {
        return null;
    }
}
